package com.sh.aspects;

import com.sh.bean.CartItem;
import com.sh.bean.TelBean;
import com.sh.utils.JmsMessageProducer;
import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Map;

@Aspect
@Component
//@Order(10)
public class TelEmailAspect {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private JmsMessageProducer jmsMessageProducer;


    @Pointcut("execution(* com.sh.web.controller.CaptchaController.getTelValcode(..))")
    private void getTelValcode() {

    }

    @Pointcut("getTelValcode()")
    private void all() {
    }


    @Before("all()")
    public void sendEmail(JoinPoint joinPoint) throws IOException {
        // 发送邮件  其实是发到消息中间件里面
        TelBean messageBean = new TelBean();
        Object[] args = joinPoint.getArgs();
        String tel=null;
        if (args.length > 0 && args[0] instanceof String) {
             tel = (String) args[0];
            System.out.println("获取到的 tel 参数值：" + tel);
        }
        messageBean.setTel(tel);
        jmsMessageProducer.sendMessage(messageBean);
    }
}
